package com.amado.course16SinglyNode;
/**
 * 数据结构-单向链表
 * 数组通过下标访问
 * 链表只能按循序一个一个查找
 * 
 * @author wangyulong
 * @date 2018-06-21
 *
 */
public class SinglyLinkedListTemp {
	SinglyNode fristNode = new SinglyNode("node1","节点1");
	SinglyLinkedListTemp(){
		init();
	}
	void init(){
		SinglyNode node2 = new SinglyNode("node2","节点2");
		SinglyNode node3 = new SinglyNode("node3","节点3");
		fristNode.setNext(node2);
		node2.setNext(node3);
	}
	/**
	 * 根据nodeCode获取节点对象
	 * @param nodeCode
	 * @return 不存在返回null
	 */
	public SinglyNode getNode(String nodeCode){
		SinglyNode nextNode = fristNode;
		//判断下一个节点不能为空
		while(nextNode!=null){
			if(nextNode.equals(nodeCode)){
				return nextNode;
			}
			nextNode = nextNode.getNext();
		}
		return null;
	}
	/**
	 * 打印节点
	 */
	public void printNode(){
		SinglyNode node = fristNode;
		while(node!=null){
			System.out.print(node.getName()+"\t");
			node = node.getNext();
			
		}
	}
	public static void main(String[] args) {
		SinglyLinkedListTemp singlyLinkedList = new SinglyLinkedListTemp();
		singlyLinkedList.printNode();
	}
	
}
